<?php


namespace app\widget;


use app\model\Column;
use app\model\Site;
use think\App;
use think\Controller;

class Pub extends Controller
{
    protected $site_id = 8;
    protected $seo_info;
    protected $site_info;
    public function initialize()
    {
        $res = Site::alias('a')->leftJoin('company b','a.company_id = b.id')->where('a.id',$this->site_id)->field('a.site_url,a.company_id,a.language_id,a.keyword,a.description,a.wx_qrcode,a.qq,a.address,a.phone,a.email,a.fax,a.hlogo,a.flogo,a.public_img,a.content,a.record,b.company_name')->find();
        $this->site_info = [
            'hlogo' => $res['hlogo'],
            'wx_qrcode'=> $res['wx_qrcode'],
            'qq' => $res['qq'],
            'address' => $res['address'],
            'phone' => $res['phone'],
            'email' => $res['email'],
            'fax' => $res['fax'],
            'flogo' => $res['flogo'],
            'public_img' => $res['public_img'],
            'content' => $res['content'],
            'record' => $res['record']
        ];
    }

    public function header()
    {
        $one_tree = Column::where(['site_id'=>$this->site_id,'pid'=>0])->field('id,title,url')->select()->toArray();
        foreach($one_tree as $key => $val){
            try{
                $two = Column::where(['site_id'=>$this->site_id,'pid'=>$val['id']])->field('id,title,url')->selectOrFail()->toArray();
                $one_tree[$key]['child'] = $two;
            }catch(\Exception $e){
                $one_tree[$key]['child'] = '';
            }

        }
        $this->assign([
            'site_info' => $this->site_info,
            'nav_tree' => $one_tree,
            'pathinfo' => '/' . $this->request->pathinfo()
        ]);
        return $this->fetch('/public/header');
    }
    public function footer()
    {
        $product = Column::alias('a')->leftJoin('column b','a.pid = b.id')->where('b.title','产品中心')->field('a.title,a.url')->select();
        $this->assign([
            'product'=>$product,
            'site_info' => $this->site_info,
        ]);
        return $this->fetch('/public/footer');
    }
}